package com.starlight.easybuyprictice.controller;

/**
 * @Author yfy2001
 * @date 2022/11/29 16:56
 */

import com.starlight.easybuyprictice.interceptor.FreeTokenAuthentication;
import com.starlight.easybuyprictice.service.ImageService;
import com.starlight.easybuyprictice.service.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
@Controller
@RequestMapping("file")
public class FileController {

    private ImageService imageService;

    @Autowired
    public FileController setImageService(ImageService imageService) {
        this.imageService = imageService;
        return this;
    }

    //上传图片
    @PostMapping("/upload")
    @ResponseBody
    @FreeTokenAuthentication
    public Result upload(@RequestParam(value = "image", required = false) MultipartFile file,@RequestParam(value = "goodId",required = false) int goodId,
                         HttpServletRequest request) {
        return imageService.uploadImage(file, goodId,request);
    }
}

